# -*- coding: utf-8 -*-
from datetime import timedelta

from jms_hi.dwd.tms.dwd_tmsnew_shipment_union_base_hi import jms_dwd__dwd_tmsnew_shipment_union_base_hi
from jms_hi.dwd.tms.dwd_tmsnew_shipment_stop_union_base_hi import jms_dwd__dwd_tmsnew_shipment_stop_union_base_hi
from jms_hi.dim.dim_tmsnew_vehicle import jms_dim__dim_tmsnew_vehicle
from jms_hi.dim.dim_tmsnew_vehicle_line import jms_dim__dim_tmsnew_vehicle_line
from jms_hi.dwd.tab.dwd_tab_barscan_other_base_hi import jms_dwd__dwd_tab_barscan_other_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_loading_base_hi import jms_dwd__dwd_tab_barscan_loading_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_unloading_base_hi import jms_dwd__dwd_tab_barscan_unloading_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_centersend_base_hi import jms_dwd__dwd_tab_barscan_centersend_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_centerarrival_base_hi import jms_dwd__dwd_tab_barscan_centerarrival_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_sitesend_base_hi import jms_dwd__dwd_tab_barscan_sitesend_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_sitearrival_base_hi import jms_dwd__dwd_tab_barscan_sitearrival_base_hi
from jms_hi.dwd.oms.dwd_yl_oms_oms_order_hf import jms_dwd__dwd_yl_oms_oms_order_hf
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

jms_dwd__dwd_wide_tms_road_waybill_hf = SparkSqlOperator(
    task_id='jms_dwd__dwd_wide_tms_road_waybill_hf',
    email=['rongguangfan@jtexpress.com','yl_bigdata@yl-scm.com'],
    master='yarn',
    name='jms_dwd__dwd_wide_tms_road_waybill_hf_{{ execution_date | cst_hour }}',
    sql='jms_hi/dwd/dwd_wide_tms_road_waybill_hf/execute.hql',
    pool_slots=3,
    driver_cores=5,
    driver_memory='8g',
    executor_cores=7,
    executor_memory='16G',
    num_executors=30,
    depends_on_past=True,
    conf={'spark.dynamicAllocation.enabled':'true',
          'spark.shuffle.service.enabled':'true',
          'spark.dynamicAllocation.maxExecutors':'120',
          'spark.dynamicAllocation.cachedExecutorIdleTimeout':'600',
          'spark.network.timeout':'600',
          'spark.sql.sources.partitionOverwriteMode':'dynamic',
          'spark.executor.memoryOverhead':'6G',
          'spark.sql.shuffle.partitions':'3600',
          'spark.memory.useLegacyMode':'true',
          'spark.shuffle.memoryFraction':'0.8',
          'spark.shuffle.io.retryWait':'60',
          'spark.reducer.maxSizeInFlight':'96M',
          'spark.shuffle.file.buffer':'96k',
          'spark.shuffle.spill.compress': 'true',
          'spark.io.compression.codec':'lz4',
          'spark.io.compression.lz4.blockSize':'256k',
          'spark.driver.extraJavaOptions':'-XX:+UseG1GC',
          # 'spark.executor.extraJavaOptions':'-XX:+UseG1GC',
          'spark.executor.extraJavaOptions':'-XX:+UseG1GC -XX:ParallelGCThreads=6'
          # 'spark.sql.autoBroadcastJoinThreshold':'104857600'
          },
    hiveconf={'hive.exec.dynamic.partition'             : 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode'        : 'nonstrict',
              'hive.exec.max.dynamic.partitions'        : 3000,  # 最大分区
              'hive.exec.max.dynamic.partitions.pernode': 3000,  # 最大分区
              'hive.optimize.bucketmapjoin': 'true',
              'hive.optimize.bucketmapjoin.sortedmerge': 'true',
              # 'hive.input.format': 'org.apache.hadoop.hive.ql.io.BucketizedHiveInputFormat',
              },
    yarn_queue='pro_hi',
    execution_timeout=timedelta(minutes=60),
    retries=1,
    sla=timedelta(hours=2),)

jms_dwd__dwd_wide_tms_road_waybill_hf << [
    jms_dwd__dwd_tmsnew_shipment_union_base_hi,
    jms_dwd__dwd_tmsnew_shipment_stop_union_base_hi,
    jms_dim__dim_tmsnew_vehicle,
    jms_dim__dim_tmsnew_vehicle_line,
    jms_dwd__dwd_tab_barscan_other_base_hi,
    jms_dwd__dwd_tab_barscan_loading_base_hi,
    jms_dwd__dwd_tab_barscan_unloading_base_hi,
    jms_dwd__dwd_tab_barscan_centersend_base_hi,
    jms_dwd__dwd_tab_barscan_centerarrival_base_hi,
    jms_dwd__dwd_tab_barscan_sitesend_base_hi,
    jms_dwd__dwd_tab_barscan_sitearrival_base_hi,
    jms_dwd__dwd_yl_oms_oms_order_hf
]
